package com.five.dao.impl.backstage;

import com.five.dao.backstage.OrderManageDao;
import com.five.entity.backstage.TRuzhudetail;
import com.five.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: 王登峰
 * @Description:
 * @Date: 2020/11/30 22:08
 */
@Repository
public class OrderManageImpl implements OrderManageDao {
    @Override
    public List<Map> selectByTid(Integer id) {
        String sql = "select a.*,b.yj from t_room a left join t_type b on a.typeid = b.id where typeid = ? and " +
                "a.status = 0";
        return DBUtil.queryMap(sql,id);
    }
    @Override
    public int ruZhuDetail(TRuzhudetail tRuzhudetail){
        String sql = "insert into t_ruzhudetail(name,tel,idcard,orderid,ruzhuid,roomid,rzyj,rzdate1,leavedate1) " +
                "values(?,?,?,?,?,?,?,?,?)";
        return DBUtil.manage(sql,tRuzhudetail.getName(),tRuzhudetail.getTel(),tRuzhudetail.getIdcard(),tRuzhudetail.getOrderid(),tRuzhudetail.getRuzhuid(),tRuzhudetail.getRoomid()
        ,tRuzhudetail.getRzyj(),tRuzhudetail.getRzdate1(),tRuzhudetail.getLeavedate1());
    }
    //改变房间的状态
    @Override
    public int changeStatus(String roomcode){
        String sql = "update t_room set status = 1 where roomcode = ?";
        return DBUtil.manage(sql,roomcode);
    }
    @Override
    public int changeStatus2(String roomcode){
        String sql = "update t_room set status = 0 where roomcode = ?";
        return DBUtil.manage(sql,roomcode);
    }
    //改变订单的状态
    @Override
    public int changeOder1(String orderid){
        String sql = "update t_order set status = 1 where orderid = ?";
        return DBUtil.manage(sql,orderid);
    }
    @Override
    public int changeOder2(String orderid){
        String sql = "update t_order set status = 2 where orderid = ?";
        return DBUtil.manage(sql,orderid);
    }
    //已经分配的房间数
    @Override
    public int roomcount(String orderid){
        String sql = "select count(*) a from t_ruzhudetail a left join t_order b on a.orderid=b.orderid where a.orderid = ?";
        List<Map> list = DBUtil.queryMap(sql, orderid);
        String s = list.get(0).get("a") + "";
        int i = Integer.parseInt(s);
        return i;
    }
    //该订单退房的次数
    @Override
    public int orderTuiFang(String orderid){
        String sql = "select count(*) a from t_tuifang where orderid = ?";
        List<Map> list = DBUtil.queryMap(sql,orderid);
        String a = list.get(0).get("a") + "";
        int i = Integer.parseInt(a);
        return i;
    }
}
